package com.situ.vivamarket.controller.sys;

import com.situ.vivamarket.model.Brand;
import com.situ.vivamarket.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("/vm/sys/brand")
public class BrandController {
    private  BrandService brandService;
    @Autowired
    public void setBrandService(BrandService brandService) {
        this.brandService = brandService;
    }

    @GetMapping("/list")
    public String list() {
        return "sys/brand/list";
    }
    @GetMapping("/add")
    public String add() {
        return "sys/brand/add";
    }
    @GetMapping("/edit")
    public String edit(Integer id, Map<String, Object> map) {
        if (id == null) {
            map.put("error","修改的ID为空");
            return "sys/brand/edit";
        }
        Brand brand = brandService.findById(id);
        if (brand == null) {
            map.put("error","要修改的品牌不存在");
        }else{
            map.put("brand",brand);
        }
        return "sys/brand/edit";

    }
}
